<?php include "top.php"; ?>

<script src="uploadify/swfobject.js"  language="javascript" ></script>
<script src="uploadify/jquery.uploadify.v2.1.4.min.js"  language="javascript" ></script>
<link href="uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<?php
		 $nid=make_safe($_GET["nid"]); 
		 $BigClassName=make_safe($_GET["BigClassName"]); 
		 
		 if($nid==""){$nid=1;}		 
		if($nid==1){$nidname="公司樣本";}
		 if($nid==2){$nidname="禮服";}
		 if($nid==3){$nidname="客戶";}
		 
		 
		?>


      <div id="top-3">
        <div id="m-text-1">
        <table border="0" cellpadding="0" cellspacing="0" class="tab-5">
   <tr>
     <td valign="top"><div class="tab-5-tit">主功能列表</div>
     <div class="m-text-2_btn"><a href="category.php?nid=<?php echo $nid;?>">作品分類管理</a></div>
     <div class="m-text-2_btn"><a href="target.php?nid=<?php echo $nid;?>" >標簽管理</a></div>
        <div class="tab-5-tit">相簿管理</div>
      
	 
	 <?php
  $n=1;

  $sql="select * from product_type_big where nid='$nid' order by orderid  ";			
	$result=mysql_query($sql);
	while ($row=mysql_fetch_object($result)){
	?>
     <div class="m-text-2_btn"><a href="working.php?nid=<?php echo $nid;?>&BigClassName=<?php echo urlencode($row->BigClassName);?>"><?php echo $row->BigClassName;?></a></div>
     <?php }?>
	 
	 
	 
       </td>
   </tr>
   </table>
        </div>
		
		
		
		
		
		
		
		
        <div id="m-text-2_banner">
          <ul>
          
           
            <li><?php echo $nidname;?>相簿管理->修改</li>
          </ul>
        </div><div id="m-text-2"></td>
   </tr>
   </table>
   
   
   
   
   <?php 
   $id=make_safe($_GET["id"]); 
   $nid=make_safe($_GET["nid"]); 
   $action=make_safe($_GET["action"]);
    
   $item=make_safe($_POST["items"]);
   
    
   $title=make_safe($_POST["title"]); 
   $content=make_safe($_POST["items"]); 
   $BigClassName=make_safe($_POST["BigClassName"]); 
   $oldimages=make_safe($_POST["oldimages"]); 
   $addtime=$data3;
   $path =  "upfiles/tmp/".$_POST['ajaxf_images'];
   $type=strstr($path,'.');
   $path2 = "upfiles/".$data."1".$type;
   $type=strtolower($type); 
   

   if($action=="xiugai"){
   
if($type==".jpg"  or $type==".jpge" or $type==".jpeg" or $type==".gif" or $type==".doc" or $type==".xls" or $type==".bmp" or $type==".pdf" ){
	//move_uploaded_file("../upfiles/tmp/".$path,"../upfiles/".$path2);//上传图片
	copy("../".$path,"../".$path2);
	unlink("../".$path);
	if($oldimages!=""){unlink("../".$oldimages);}//删除旧图片
}
else
{
	$path2=$oldimages;
}

  
if($query=mysql_query("update product set title='$title',entitle='$entitle',content='$content',BigClassName='$BigClassName',enBigClassName='$enBigClassName',addtime='$addtime',images='$path2',images2='$path4',images3='$path6',images4='$path8',images5='$path10',images6='$path12',images7='$path14',images8='$path16' where id='$id'"))

{
   echo "<script>alert('資料修改成功！');window.location.href='working.php?BigClassName=".$BigClassName."&nid=".$nid."&page=".$page."';</script>";
 }
 
 else
  {
   echo "<script>alert('資料修改失敗！');window.location.href='working.php?BigClassName=".$BigClassName."&nid=".$nid."&page=".$page."';</script>";
  }
   
   
   }
   
   
   ?>
   
   
     <script language="javascript"> 



function Checker(){ 


  
// document.write(document.form2.id.length)
  
  
  
   //if(document.form2.yaoyun.value==""){document.write("您按了确认！") }
   
   //  document.write("您按了确认！") 

   

document.form2.items.value = "";         //设置隐藏域的值为空
if ( !document.form2.id.length ) {      //只有一个复选框，form2.item.length = undefined



	if ( document.form2.id.checked ){
	document.form2.items.value = document.form2.id.value; 
	
	
	} 
}else { 

	var temp="";
	for ( i = 0 ; i < document.form2.id.length ; i++ ){ 
		if ( document.form2.id[i].checked ){       //复选框中有选中的框 
			temp=temp+document.form2.id[i].value+",";   //将数组中的元素使用","分隔
		}	 

	} 
	temp=temp.substring(0,temp.length-1);     //去除字符串末尾多余的","
	document.form2.items.value = temp;    //将变量赋值给隐藏域
	
//	document.write(document.form2.items.value)
} 
} 
</script>  

<script language="javascript">
function CheckAll(elementsA,elementsB)
{
	var len = elementsA;
	if(len.length > 0)
	{
		for(i=0;i<len.length;i++)
		{
			elementsA[i].checked = true;
		}
		if(elementsB.checked ==false)
		{
			for(j=0;j<len.length;j++)
			{
				elementsA[j].checked = false;
			}
		}
	}
	else
	{
		len.checked = true;
		if(elementsB.checked == false)
		{
			len.checked = false;
		}
	}
}
</script>
   
    
   
   <?php 
   $id=make_safe($_GET["id"]); 
	 $sql="select * from product where id='$id' ";			
	 $result=mysql_query($sql);
	 while ($row=mysql_fetch_object($result)){
	 ?>
   <form name="form2" action="?action=xiugai&nid=<?php echo $row->nid;?>&id=<?php echo $row->id;?>" method="post" enctype="multipart/form-data" target="_self" onSubmit="Checker()">
        <table border="0" cellpadding="0" cellspacing="0" class="m-text-2-imp">
          <tr>
            <td class="m-text-2-con2">相簿名稱：
             
              <select name="title" >
			  
			  <?php
  $n=1;

  $sql2="select * from product where nid='$nid' order by id  ";			
	$result2=mysql_query($sql2);
	while ($row2=mysql_fetch_object($result2)){
	?>
    
	 <option  value="<?php echo $row2->title;?>"   <?php if($row->title==$row2->title){echo "selected";}?>><?php echo $row2->title;?></option>
	
     <?php }?>
			  
                
              </select></td>
            <td class="m-text-2-con3">&nbsp;</td>
          </tr>	  
		  
        </table>
		
		
	
		
		<table border="0" cellpadding="0" cellspacing="0" class="m-text-2-imp">
		
		<?php 
		  $aa=getimagesize("../".$row->images);
$weight=$aa["0"];////获取图片的宽
$height=$aa["1"];///获取图片的高

if($weight>=$height){$weight1=160;$height1=160*$height/$weight;}
if($height>=$weight){$height1=160;$weight1=160*$weight/$height;}
		
		?>
		
		
		<tr>
            <td class="m-text-2-con2">原圖：
			
            <?php if(strlen($row->images) > 0):?>
 				<img id="images_img" src="../<?php echo $row->images;?>" width="<?php echo $weight1;?>" height="<?php echo $height1;?>" border="0"  />
 			<?php else:?>
 				<img id="images_img" src="../pic/blank.gif" width="<?php echo $weight1;?>" height="<?php echo $height1;?>" border="0"  />
 			<?php endif;?>
              </td>
            <td class="m-text-2-con3">&nbsp;</td>
          </tr>
		
		
		
		<script language="javascript">
			$(function(){
				$(".uploadifyupload").each(function(){
					var current_id = $(this).attr('id');
					var previous_img_id = current_id + '_img';
					$(this).uploadify({
						'uploader': 'uploadify/uploadify.swf',
						'cancelImg': 'uploadify/cancel.png',
						'script': 'upload.php',
						'folder': 'files',
						'buttonText':'Choose',
						'multi': false,
						'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
  						'fileDesc':'Image Files',
						'auto': true,
						'queueSizeLimit':1,
						'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','name':$(this).attr('name'),'responsetype':'sizeinfo'},
						'displayData': 'speed',
						'onComplete':function(event,queueID,fileObj,response,data){
							var responseObj = eval("("+response+")");
							var fileName = responseObj.name;
							$('#'+previous_img_id).attr('src','../upfiles/tmp/' + fileName);
							$('input[name=ajaxf_'+current_id+']').val(fileName);
							
						},
						'onError':function(event,queueId,fileObj,errorObj){
							alert(errorObj);
						}
					});
				});
			});
		</script>
          <tr>
            <td class="m-text-2-con2">上傳圖片：
 			 <input type="hidden" name="ajaxf_images" value=""/>
 			  <input type="hidden" name="oldimages" value="<?php echo $row->images;?>"/>
              <input id="images" name="images" type="file" class="uploadifyupload" size="60">
             </td>
            <td class="m-text-2-con3">&nbsp;</td>
          </tr>	  
		  
        </table>
		
        <table border="0" cellpadding="0" cellspacing="0" class="m-text-2-imp">
          <tr>
            <td class="m-text-2-con2">選擇相簿類別：
              <label for="select"></label>
              <select name="BigClassName" >
			  
			  <?php
  $n=1;

  $sql2="select * from product_type_big where nid='$nid' order by orderid  ";			
	$result2=mysql_query($sql2);
	while ($row2=mysql_fetch_object($result2)){
	?>
    
	 <option  value="<?php echo $row2->BigClassName;?>"   <?php if($row->BigClassName==$row2->BigClassName){echo "selected";}?>><?php echo $row2->BigClassName;?></option>
	
     <?php }?>
			  
                
              </select>              
              <label for="textfield2"></label></td>
            <td class="m-text-2-con3"><input type="hidden" name="items" value="<?php echo $item; ?>"></td>
          </tr>
        </table>
		
		
		
		
		<div id="m-text-3">
		
		
		
		
		
		
		<?php
  $n=1;

  $sql3="select * from target where nid='$nid' order by id  ";			
	$result3=mysql_query($sql3);
	while ($row3=mysql_fetch_object($result3)){
	?>
<table border="0" cellpadding="0" cellspacing="0" class="m-text-2-con-2">
  <tr>
    <td class="m-text-2-con1"><input name="id" type="checkbox" id="id" value="<?php echo $row3->id;?>" 
	
	
	<?php 
	$array=explode(",",$row->content);
	for($i=0;$i<count($array);$i++){ 
	
	
	
	if($array[$i]==$row3->id){echo "checked='checked'";}
	}
	?> 
	
	>
    </td>
    <td class="m-text-2-con-21"><?php echo $row3->content;?></td>
  </tr>
</table>
<?php }?>







<table border="0" cellpadding="0" cellspacing="0" id="m-text-2-edit">
          <tr>
            <td class="m-text-2-con2"> </td>
            <td class="m-text-2-con3"><input type="submit" name="button2" id="button2" value="修改" /></td>
          </tr>
        </table>
        </div>
		
		
		
		
   </form>
   <?php }?>
   
   
 
   
        </div>
      </div>
    </div>
  </div>
</div>
<div id="botton"><div id="copyright"><table border="0" cellpadding="0" cellspacing="0" class="copy">
  <tr>
    <td>© COPYRIGHTS 2010 INC. APARTMENT STUDIO All rights reserved.</td>
  </tr>
</table>
</div></div>
</body>
</html>